<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>内容管理</title>
<link href="/res/back/css/base.css" rel="stylesheet" type="text/css" />
<link href="/res/third/bootstrap3/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="/res/common/js/jquery.1.9.1.min.js" type="text/javascript"></script>
<script src="/res/third/artDialog/jquery.artDialog.js" type="text/javascript"></script>
<script src="/res/third/validate/jquery.validate.js" type="text/javascript"></script>
<script src="/res/third/easyUI/jquery.easyui.min.js" type="text/javascript"></script>
<script src="/res/third/easyUI/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
<link href="/res/third/powerFloat/css/powerFloat.css" rel="stylesheet" type="text/css" />
<script src="/res/third/powerFloat/js/mini/jquery-powerFloat-min.js" type="text/javascript"></script>
<script type="text/javascript" src="/res/third/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="/res/third/ueditor/ueditor.all.js"></script>
<script type="text/javascript" src="/res/third/ueditor/lang/zh-cn/zh-cn.js"></script>
<style type="text/css">
		.lpdiv{display: inline-block;float: left;margin-left: 220px;margin-top: 15px;width: 100%;}
		.showimgs{display:inline-block;}
		.delimgas{display:inline-block;margin-left:50px;cursor:pointer;}
</style>
<script type="text/javascript">

[#if canAdd?? && !canAdd]
alert("奖品数量超过11个，请先删除再添加！");
top.closeTempTab(true);
[/#if]

 //提交判断
   function save(){
	   var prizeset={};
	   var giftCode=$("#giftCode").val().trim();
		if(giftCode==""){
			alert("奖品编号不能为空");
			return false;
		}
		var seq=$("#seq").val().trim();
		if(seq==""){
			alert("奖品排序不能为空");
			return false;
		}
		var giftName=$("#giftName").val().trim();
		if(giftName==""){
			alert("奖品名称不能为空");
			return false;
		}
		var giftPrice=$("#giftPrice").val().trim();
		var t=/^([1-9]\d*|0)(\.\d{1,2})?$/;
		if(!t.test(giftPrice)){
			alert("请输入正确的礼品价格模式");
			return false;
		}
		var probability=$("#probability").val().trim();
		if(probability==""){
			alert("请输入中奖概率");
			return false;
		}
		var overdueDate=$("[name='overdueDate']").val().trim();
		if(overdueDate==""){
			alert("请输入过期日期");
			return false;
		}
		
		var imgUrlCount=$(".showimgs").length;
		if(imgUrlCount==0){
			alert("请上传至少一张图片");
			return false;
		}
		
		var stockAmount=$("#stockAmount").val().trim();
		if(stockAmount==""){
			alert("请输入奖品库存");
			return false;
		}
		var perdayAmount=$("#perdayAmount").val().trim();
		if(perdayAmount==""&& perdayAmount>amount){
			alert("提示:请输入正确的每日最高中奖数量并且不能多于奖品数量");
			return false;
		}
	   $.ajax({
		  type:"post",
		  dataType:"json",
		  url:"/prize/updat.do",
		  data:$("form").serialize(),  
		  beforeSend:function(){
				 art.dialog.tips("加载中");
			  },
			  success:function(da){
				  if(da.success){
					  alert(da.msg);
                      top.closeTempTab(true);//转到父级的页面
				  }
			  }
	   });
   }
   
 //时间插件
   $(function() {

	    $("#startdate").datebox({
	        formatter: function (date) {
	            var y = date.getFullYear();
	            var m = date.getMonth() + 1;
	            var d = date.getDate();
	            return y + '-' + m + '-' + d;
	        },
	        onSelect: function (dateselect) {
	            //enddate清空
	            $('#enddate').datebox('setValue', '');
	            $("#enddate").datebox("calendar").calendar({
	                validator: function (date) {
	                    return dateselect <= date;
	                }
	            });
	        }
	    });
    //时间插件
	    $("#enddate").datebox({
	        formatter: function (date) {
	            var y = date.getFullYear();
	            var m = date.getMonth() + 1;
	            var d = date.getDate();
	            return y + '-' + m + '-' + d;
	        }
	    })
	    
	}) 
   
 //上传文件的类型gif,jpg等
 var exceldialog=null;
 function addpicture(){
 	exceldialog = art.dialog.uploadFile("上传礼品",{callback:"uploadcallback",userpath:"admin",extensions:"gif,jpg,png,jepg"});
 }
 
 
 //把图片地址打在页面上
 function uploadcallback(response){
		exceldialog.close();
		$("#mainlpdiv").append("<div class='lpdiv'>"
				+"<input type='hidden' name='imgUrl' value='"+response.url+"'  />"
				+"<a target='_blank' class='showimgs' href='"+response.url+"'>"+response.url+"</a>"
				+"<a onclick='delimgs(this)' class='delimgas'>删除</a></div>");
	}

	function delimgs(node){
		$(node).parents(".lpdiv").remove();
	}
	
</script>

</head>
<body>
    <div class="panel panel-info" style="height: 100%;overflow-y:scroll;">
	      
        <div class="panel-body" style="overflow: hidden;border-bottom: none;">
			<form class="form-horizontal" role="form"   id="mainForm">
			  <input type="hidden" name="id" value="${(selectone.id)!}">
			  <div class="form-group" style="margin-top:15px;">
			    <label for="title" class="col-sm-2 control-label"><span style="color:red;">*</span>奖品编号</label>
			    <div class="col-sm-5">
			      <input type="text"  class="form-control" id="giftCode" placeholder="请输入礼品编号" value="${(selectone.giftCode)!}" name="giftCode" required="required">
			    </div>
			  </div>
			  <div class="form-group">
			    <label for="title" class="col-sm-2 control-label">奖品类型</label>
			    <div class="col-sm-5">
			      <select name="type">
				      <option [#if ((selectone.type)!0) == 1]selected[/#if] value="1">虚拟</option>
				      <option [#if ((selectone.type)!0) == 2]selected[/#if] value="2">实物</option>
				      <option [#if ((selectone.type)!0) == 3]selected[/#if] value="3">积分</option>
				  </select>
			    </div>
			  </div>
			  <div class="form-group">
			    <label for="title" class="col-sm-2 control-label"><span style="color:red;">*</span>奖品排序</label>
			    <div class="col-sm-5">
			      <input type="number" class="form-control" id="seq" placeholder="请输入奖品排序" name="seq" value="${(selectone.seq)!}" required="required">
			    </div>
			  </div>
			  <div class="form-group">
			    <label for="title" class="col-sm-2 control-label"><span style="color:red;">*</span>奖品名称</label>
			    <div class="col-sm-5">
			    <input type="text" class="form-control" id="giftName" placeholder="请输入奖品名称" name="giftName" value="${(selectone.giftName)!}" required="required">
			    </div>
			  </div>
			  <div class="form-group">
			    <label for="title" class="col-sm-2 control-label"><span style="color:red;">*</span>奖品价值</label>
			    <div class="col-sm-5">
			      <input type="text" class="form-control" id="giftPrice" placeholder="请输入奖品价值" name="giftPrice" value="${(selectone.giftPrice)!}" required="required">
			    </div>
			  </div>
			  <div class="form-group">
			    <label for="title" class="col-sm-2 control-label"><span style="color:red;">*</span>中奖概率</label>
			    <div class="col-sm-5">
			     1/<input type="number" class=" " id="probability" placeholder="请输入中奖概率" name="probability" value="${(selectone.probability)!}" required="required">
			    </div>
			  </div>
			  <div class="form-group">
			    <label for="title" class="col-sm-2 control-label"><span style="color:red;">*</span>过期时间</label>
			    <div class="col-sm-5">
			     <input id="startdate" style="width:120px;" name="overdueDate" value="${(selectone.overdueDate?string('yyyy-MM-dd'))!}" required="required" >
			    </div>
			   </div>
			    <div class="form-group" id="mainlpdiv">
			    <label for="title" class="col-sm-2 control-label"><span style="color:red;">*</span>礼品图片</label>
			    <div class="col-sm-8">
					<button onclick="addpicture()" type="button" class="btn btn-default"  id="imgUrl" required="required">礼品图片</button>
				</div>
				[#if selectone?? && selectone.imgUrl??]
				  <div class="lpdiv">
					  <input type='hidden' name='imgUrl' value='${selectone.imgUrl!}'>
		    <!--  路径    -->		<a target="_blank" class="showimgs" href="${selectone.imgUrl!}">${selectone.imgUrl!}</a>
			<!-- 删除键 -->	    <a onclick="delimgs(this)"  class="delimgas">删除</a>
				  </div>
				[/#if]
			  </div>
			 
			  <div class="form-group" id="mainlpdiv">
			    <label for="title" class="col-sm-2 control-label"><span style="color:red;">*</span>奖品库存</label>
			    <div class="col-sm-5">
			      <input type="text" class="form-control" id="stockAmount" placeholder="请输入数量" name="stockAmount" value="${(selectone.stockAmount)!}" required="required">
			    </div>
			  </div>
			  <div class="form-group">
			    <label for="title" class="col-sm-2 control-label"><span style="color:red;">*</span>每日最高中奖数量</label>
			    <div class="col-sm-5">
			        <input type="text" class="form-control" id="perdayAmount" placeholder="请输入每日最高中奖数量" name="perdayAmount" value="${(selectone.perdayAmount)!}" required="required">
			    </div>
			  </div>
			  <div class="form-group">
			    <div class="col-sm-offset-2 col-sm-10">
			      <button type="button" class="btn btn-info" onclick="save();">保存</button>
			    </div>
			  </div>
			</form>
        </div>
      </div>
</body>
</html>